package controller

import (
	"github.com/gin-gonic/gin"
	"github.com/lostvip-com/lv_framework/lv_global"
	"log"
	"main/internal/zodiac/service"
	"main/internal/zodiac/storage"
	"time"
)

type AriesController struct{}

func (w AriesController) History(c *gin.Context) {
	base_currency := c.Query("base_currency")
	record_date := c.DefaultQuery("record_date", time.Now().Format("2006/01/02"))
	//var api service.ExchangeApi
	var storage storage.MySqlRateHistoryRepository
	exchangeApi := service.NewExchangeApi(
		lv_global.Config().GetConf("zodiac.aries.exchange-api-url"), &storage)
	history, err := exchangeApi.History(base_currency, record_date)
	if err != nil {
		log.Fatalf("Error binding JSON: %v", err)
	}

	c.JSON(200, gin.H{
		"data": history,
	})
}
